package com.wjr.view;

import com.wjr.entity.MyTank;
import com.wjr.entity.Wall;
import com.wjr.property.GameWindowProperty;
import com.wjr.utils.CreateWallByRandom;

import javax.swing.*;
import java.awt.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;


public class GamePanel extends JPanel {

    public static List<Wall> wallList = new LinkedList<>();

    private MyTank myTank;
    private Wall wall;
    boolean flag = true;
    Random random = new Random();

    public GamePanel(MyTank myTank,Wall wall){

        this.myTank = myTank;
        this.wall = wall;
        new updateGame().start();

    }

    //画笔，可画出游戏元素
    @Override
    public void paint(Graphics graphics) {
        //设置游戏背景
        graphics.setColor(Color.white);
        graphics.fillRect(0,0, GameWindowProperty.WIDTH,GameWindowProperty.HEIGHT);

        //画出我方坦克
        if (myTank != null && myTank.isLive){
            myTank.drawMe(graphics);
        }

        //
    }

    class updateGame extends Thread{

        @Override
        public void run() {
            while (flag){
                repaint();
            }
        }
    }
}
